The pharmaceutical industry faces unique challenges in clinical and statistical programming:
Implementing patterns used across many table shells (developed by dedicated teams)
Company-specific statistical methods that need to be standardized
Complex table structures that must be consistent across studies
Need for a core framework that ensures all company shells can be created consistently
Shells Are Table Specific, Table Creation Is Not
The Junco Package Approach
Our solution was to develop our own business logic framework for J&J table creation
Getting to Production
The Junco package provides key features needed for production-ready clinical tables:
True-type font support: Word wrapping, pagination, and RTF export
Higher order column counts: Utilities for spanning column headers
Guaranteed pathability in row space
Nearest-value (SAS-like) rounding support: Maintaining consistency with existing processes
Statistical calculations: In accord with business logic
Robust approach for risk diff columns
Creating the package
From Scripts to Standardized Tools
Industry Benefits
Creating internal R packages helps pharmaceutical companies:
Maintain consistency across studies and therapeutic areas
Reduce time spent on repetitive coding tasks
Improve compliance with regulatory standards
Facilitate knowledge transfer between team members
Code Design and API for Users
Once we had the core functionality working, we needed to focus on:
User-friendly API: Creating intuitive functions that match users’ mental models
Consistent interfaces: Ensuring functions work together seamlessly
Clear documentation: Making the package accessible to non-developers
Comprehensive testing: Validating functionality across different scenarios
Continuous integration: Automating quality checks and deployment
Version control: Managing changes and updates systematically
Documentation: Making Your Package Accessible
Using roxygen2 and pkgdown
Documentation is critical for package adoption and proper use:
roxygen2 for function documentation:
#' Calculate risk difference with confidence intervals#'#' @param group1 Vector of outcomes for first group#' @param group2 Vector of outcomes for second group#' @param conf.level Confidence level (default: 0.95)#' @return A list with risk difference and Cis#' @exportrisk_diff <-function(group1, group2, conf.level =0.95) {# Function implementation}
pkgdown for website generation:
usethis::use_pkgdown()pkgdown::build_site()
Ensuring Package Quality
Unit Testing and Validation
Quality assurance is essential for pharmaceutical applications:
Unit tests: Verify each function works as expected
Integration tests: Ensure components work together correctly
Regression tests: Prevent reintroduction of fixed bugs
Include detailed information about validation status and intended use cases to help users understand if the package meets their regulatory requirements.
Continuous Integration and Deployment
Automating Quality Checks
CI/CD reduces manual work while improving quality:
GitHub packages: Community collaboration, rapid development
Pharmaceutical Considerations
Internal packages often contain proprietary methods or company-specific workflows that shouldn’t be publicly shared, while more general statistical methods may benefit from community review through CRAN or GitHub distribution.
Case Study: Clinical Trial Analysis Package
From Scripts to Package
Example transformation of repetitive clinical trial analysis scripts:
Identify common functions across multiple studies
Standardize input/output formats
Create consistent documentation
Implement validation tests
Deploy to internal repository
Summary
Key Takeaways
R packages provide a structured framework for organizing code
They improve reproducibility and reduce errors
Documentation and testing are essential components
Packages can streamline workflows in pharmaceutical research
The investment in package development pays off through reuse and reliability